package com.jsnkj.basic.adapter

import android.app.Activity
import android.graphics.Bitmap
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.jsnkj.basic.R
import com.jsnkj.basic.bean.InviteBannerBean
import com.jsnkj.basic.util.SharePreferencesUtil
import com.bumptech.glide.Glide
import com.youth.banner.adapter.BannerAdapter


open class InviteBannerAdapter(
    val activity: Activity,
    itemList: List<InviteBannerBean>,
) :
    BannerAdapter<InviteBannerBean, InviteBannerAdapter.BannerViewHolder>(itemList) {


    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        val view: View =
            LayoutInflater.from(parent.context)
                .inflate(R.layout.rv_item_invite_banner, parent, false)
        return BannerViewHolder(view)
    }

    override fun onBindView(
        holder: BannerViewHolder, bean: InviteBannerBean, position: Int, size: Int
    ) {
        Glide.with(activity).load(bean.imgQR).into(holder.imgQR)
        Glide.with(activity).load(bean.imgId).into(holder.imgBg)
        Glide.with(activity).load(bean.imgTextBgId).into(holder.ivTextBg)

        holder.tvItemContent.text = "我在${activity.getString(R.string.app_name)}\n最高领99元"

        SharePreferencesUtil.getInstance().getUserBean()?.let {
            it.user?.let { user ->
                Glide.with(activity).load(user.avatar).into(holder.ivUserAvatar)
                holder.ivUserName.text = user.showName()
                holder.ivUserId.text = "会员ID：${user.uuid}"
            }
        }

    }

    class BannerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var imgBg: ImageView
        var imgQR: ImageView
        var ivTextBg: ImageView
        var ivUserAvatar: ImageView
        var ivUserName: TextView
        var ivUserId: TextView
        var tvItemContent: TextView
        var conLayoutBg: ConstraintLayout

        init {
            imgBg = itemView.findViewById(R.id.img_bg)
            imgQR = itemView.findViewById(R.id.img_qr)
            ivTextBg = itemView.findViewById(R.id.img_text_bg)
            ivUserAvatar = itemView.findViewById(R.id.iv_user_avatar)
            ivUserName = itemView.findViewById(R.id.tv_user_name)
            ivUserId = itemView.findViewById(R.id.tv_user_id)
            conLayoutBg = itemView.findViewById(R.id.con_layout_bg)
            tvItemContent = itemView.findViewById(R.id.tv_item_content)
        }
    }


    interface onItemClickListener {
        fun onItemCallBack(bitmap: Bitmap?)
    }
}